from rest_framework import serializers
from deviceManage import models

class DeviceTypeSeriallizer(serializers.ModelSerializer):
    """
    设备类型序列化
    """

    class Meta:
        model = models.DeviceType
        fields = '__all__'

class DeviceSeriallizer(serializers.ModelSerializer):
    """
    设备序列化
    """
    type_name = serializers.CharField(source='type.name', required=False)
    room_name = serializers.CharField(source='room.name', required=False)
    class Meta:
        model = models.Device
        fields = ['id', 'name', 'uuid', 'type_id', 'type_name', 'room_id', 'room_name', 'sort',
                  'online', 'status', 'ip', 'icon']

class AlarmSeriallizer(serializers.ModelSerializer):

    device_name = serializers.CharField(source='device.name', required=False)
    room_name = serializers.CharField(source='device.room.name', required=False)
    class Meta:
        model = models.Alarm
        fields = ['id', 'createtime', 'device_id', 'device_name', 'room_name', 'reason', 'recovertime']